package com.manage.system.web.controller;

import com.manage.common.core.result.JsonResult;
import com.manage.common.log.annotation.OperateLog;
import com.manage.common.log.enums.BusinessType;
import com.manage.common.permissions.annotation.HasPermissions;
import com.manage.system.api.entity.SysOperateLog;
import com.manage.system.api.request.log.OperateLogQueryParam;
import com.manage.system.api.service.ISysOperateLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangqing
 * @description 系统操作日志日志控制层
 * @date 2021/4/26 8:00 下午
 */
@RestController
@RequestMapping("/operate-log")
@AllArgsConstructor
@Api(tags = "系统操作日志", value = "SysOperateLogController")
public class SysOperateLogController {

    private final ISysOperateLogService sysOperateLogService;

    @ApiOperation("[Remote->Feign] 添加操作日志")
    @PostMapping(value = "/addOperateLog")
    public void addOperateLog(@RequestBody SysOperateLog sysOperateLog){
        sysOperateLogService.addLoginLog(sysOperateLog);
    }

    @ApiOperation("(分页)查询操作日志")
    @PostMapping(value = "/findOperateLogPage")
    public JsonResult findOperateLogPage(@RequestBody OperateLogQueryParam operateLogQueryParam){
        return sysOperateLogService.findOperateLogPage(operateLogQueryParam);
    }

    @ApiOperation("删除操作日志")
    @DeleteMapping("/delOneOperateLog/{operateLogId}")
    @HasPermissions("log:operateLog:remove")
    @OperateLog(title = "根据ID,删除单个操作日志",module = "操作日志", businessType = BusinessType.DELETE)
    public JsonResult delOneOperateLog(@PathVariable Long operateLogId) {
        return sysOperateLogService.delOneOperateLog(operateLogId);
    }

    @ApiOperation("清空全部操作日志")
    @DeleteMapping("/delAllOperateLog")
    @HasPermissions("log:operateLog:remove")
    @OperateLog(title = "删除全部操作日志",module = "操作日志", businessType = BusinessType.DELETE)
    public JsonResult delAllOperateLog() {
        return sysOperateLogService.delAllOperateLog();
    }

    @ApiOperation("批量删除操作日志")
    @DeleteMapping("/batchDelOperateLog")
    @HasPermissions("log:operateLog:remove")
    @OperateLog(title = "批量删除操作日志",module = "操作日志", businessType = BusinessType.DELETE)
    public JsonResult batchDelOperateLog(@RequestBody List<Long> operateLogIds) {
        return sysOperateLogService.batchDelOperateLog(operateLogIds);
    }
}
